package com.itheima.demo1.ZengDemo1;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName test1
 * @Author 16799
 * @Date 2025/9/29 16:48
 * @Version 1.0
 * @Description TODO
 **/
public class test1 {
    public static void main(String[] args) throws Exception {
        List<order> orders = new ArrayList<>();

        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read("D:\\Idea\\IntelliJIDEA2023.3.2\\Code\\javaseProMax\\Day14JavasePro-HuangPuBan-Test\\src\\orders.xml");
        Element root = document.getRootElement();

        List<Element> orderEles = root.elements();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        for (Element orderEle : orderEles) {
            order order = new order();
            order.setId(Integer.valueOf(orderEle.attributeValue("id")));
            order.setName(orderEle.elementText("name"));
            order.setTime(LocalDateTime.parse(orderEle.elementText("time"),dtf));
            order.setPrice(Double.valueOf(orderEle.elementText("double")));
            orders.add(order);
        }
        orders.stream().forEach(s-> System.out.println(s));

        System.out.println("------------------订单时间在今天2025年9月29日17:24:15之前的-----------------");
        orders.stream().filter(s->s.getTime().isBefore(LocalDateTime.now())).forEach(s-> System.out.println(s));

        System.out.println("--------找价格最高的-----------");
        System.out.println(orders.stream().max((o1, o2) -> Double.compare(o1.getPrice(), o2.getPrice())).get());

        System.out.println("---------------降序----------");
        orders.stream().sorted((o1, o2) -> Double.compare(o2.getPrice(),o1.getPrice())).forEach(System.out::println);

    }
}
